home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2010 April / PCWorld0410.iso / hity wydania / Ubuntu 9.10 PL / karmelkowy-koliberek-desktop-9.10-i386-PL.iso / casper / filesystem.squashfs / etc / bash_completion.d / dkms < prev    next >
Text File  |  2009-04-24  |  2KB  |  120 lines

  1. # bash completion for dkms
  2. # Copied from the Mandriva dkms package
  3.  
  4. # This function complete on available kernels
  5. #
  6. _kernels()
  7. {
  8.         COMPREPLY=( $( cd /lib/modules && compgen -d -- "$cur" ) )
  9. }
  10.  
  11. # complete on full directory names under $1
  12. _subdirectories()
  13. {
  14.     COMPREPLY=( $( cd $1 && compgen -d -- "$cur" ) )
  15. }
  16.  
  17. # complete on $2 part of filenames matching pattern $1 under /usr/src
  18. _filename_parts()
  19. {
  20.     COMPREPLY=( $( command ls -F /usr/src/ 2>/dev/null | grep -E '^'$1'/$' \
  21.         | sed -r -e 's/^([^-]+)-(.+)\/$/\'$2'/' | grep "^$cur" ) )
  22. }
  23.  
  24. _dkms()
  25. {
  26.     local cur prev command module i
  27.  
  28.     COMPREPLY=()
  29.     cur=${COMP_WORDS[COMP_CWORD]}
  30.  
  31.     if [[ $COMP_CWORD -eq 1 ]] ; then
  32.         COMPREPLY=( $( compgen -W "add remove build install uninstall \
  33.             match mkdriverdisk mktarball ldtarball mkrpm mkdeb mkdsc mkkmp \
  34.             status" -- $cur ) )
  35.     else
  36.  
  37.         prev=${COMP_WORDS[COMP_CWORD-1]}
  38.         command=${COMP_WORDS[1]}
  39.         case $prev in
  40.             -m)
  41.                 if [ "$command" = 'add' ]; then
  42.                     _filename_parts '.*-.*' 1
  43.                 else
  44.                     _subdirectories /var/lib/dkms
  45.                 fi
  46.                 return 0
  47.                 ;;
  48.             -v)
  49.                 for (( i=1; i < COMP_CWORD; i++ )); do
  50.                     if [[ "${COMP_WORDS[i]}" == -m ]]; then
  51.                         module=${COMP_WORDS[i+1]}
  52.                         break
  53.                     fi
  54.                 done
  55.                 if [ -n "$module" ]; then
  56.                     if [ "$command" = 'add' ]; then
  57.                         _filename_parts "$module-.*" 2
  58.                     else
  59.                         _subdirectories /var/lib/dkms/$module
  60.                     fi
  61.                     return 0
  62.                 fi
  63.                 ;;
  64.             -k)
  65.                 _kernels
  66.                 return 0
  67.                 ;;
  68.             -@\(c|-spec|-archive|-config\))
  69.                 _filedir
  70.                 return 0
  71.                 ;;
  72.             --kernelsourcedir)
  73.                 _filedir -d
  74.                 return 0
  75.                 ;;
  76.         esac
  77.  
  78.  
  79.         if [[ "$cur" == -* ]]; then
  80.             case $command in
  81.                 add)
  82.                     options='-c --rpm_safe_upgrade'
  83.                     ;;
  84.                 remove)
  85.                     options='--rpm_safe_upgrade'
  86.                     ;;
  87.                 build)
  88.                     options='--config'
  89.                     ;;
  90.                 mkdriverdisk)
  91.                     options='-d --distro -r --release --size'
  92.                     ;;
  93.                 ldtarball)
  94.                     options='--archive --force'
  95.                     ;;
  96.                 mktarball)
  97.                     options='--source-only --binaries-only'
  98.                     ;;
  99.                 mkrpm)
  100.                     options='--source-only'
  101.                     ;;
  102.                 mkkmp)
  103.                     options='--spec'
  104.                     ;;
  105.                 match)
  106.                     options='--templatekernel'
  107.                     ;;
  108.             esac
  109.  
  110.             options="$options -m -v -k -a --arch -q --quiet -V \
  111.                 --version --all --no-prepare-kernel \
  112.                 --no-clean-kernel --kernelsourcedir \
  113.                 --directive"
  114.  
  115.             COMPREPLY=( $( compgen -W "$options" -- $cur ) )
  116.         fi
  117.     fi
  118. }
  119. complete -F _dkms dkms
  120.